
##
## usage:  f = sift(x, F, w)
##  
## Slow inverse Fourier transformation 
##
##        /
## f(x) = | F(w) exp(ikw) dw
##        / 
##
## Input variables:
##  f      : Data to be transformed (vector)
##  x      : Free variable (vector)
##  w      : Frequency (vector) 
##
## Returns f 
##
## Copyright (C), 2014, Jesper Hansen. 
## See the COPYING file for license agreements.
##

function F = sift(x, f, freq)
 
  if( isvector(f) != 1 || isvector(freq) != 1 )
    error("sift: 1 and 2 argument must be vectors");
  elseif ( length(freq) != length(f) )
    error("sift: Length of first  and second argument must be the same");
  endif
       
  if ( rows(f) != 1 )
    f = f';
  endif 
  if ( rows(x) != 1 )
    x = x';
  endif 

  l = length(x);
  
  F_real = zeros(l, 1);
  F_imag = zeros(l, 1);
  
  for n=1:l
    g = f.*exp(I*freq.*x(n));
    F_real(n) = trapz(freq, real(g));
    F_imag(n) = trapz(freq, imag(g));
  endfor
  
  F = F_real + I.*F_imag;
     
endfunction 
